cmake_minimum_required(VERSION "2.8")

project(logger)

if(NOT CMAKE_INSTALL_PREFIX)
    set(CMAKE_INSTALL_PREFIX output)
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)

### library
set (${PROJECT_NAME}_sources
    logger.c
)

add_library(${PROJECT_NAME} SHARED
    ${${PROJECT_NAME}_sources}
)

install(FILES logger.h DESTINATION include)
install(TARGETS "${PROJECT_NAME}" DESTINATION lib)

### tests
include(CTest)
enable_testing()

if(BUILD_TESTING)
### test 0
set(${PROJECT_NAME}_test_sources
    tests_logger_test.c
)

add_executable(${PROJECT_NAME}_test 
    ${${PROJECT_NAME}_test_sources}
)

target_link_libraries(${PROJECT_NAME}_test 
    ${PROJECT_NAME}
)

add_test(NAME ${PROJECT_NAME}_test
        COMMAND ${PROJECT_NAME}_test
)

install(TARGETS "${PROJECT_NAME}_test" DESTINATION bin)

### test 1
set(${PROJECT_NAME}_assert_test_sources
    tests_assert_test.c
)

add_executable(${PROJECT_NAME}_assert_test
    ${${PROJECT_NAME}_assert_test_sources}
)

target_link_libraries(${PROJECT_NAME}_assert_test 
    ${PROJECT_NAME}
)

add_test(NAME ${PROJECT_NAME}_assert_test
        COMMAND ${PROJECT_NAME}_assert_test
)

install(TARGETS "${PROJECT_NAME}_assert_test" DESTINATION bin)
endif()